package com.ruoyi.project.system.album.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.album.domain.BizAlbum;
import com.ruoyi.project.system.album.service.IBizAlbumService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 相册Controller
 * 
 * @author ruoyi
 * @date 2020-05-01
 */
@Controller
@RequestMapping("/system/album")
public class BizAlbumController extends BaseController
{
    private String prefix = "system/album";

    @Autowired
    private IBizAlbumService bizAlbumService;

    @RequiresPermissions("system:album:view")
    @GetMapping()
    public String album()
    {
        return prefix + "/album";
    }

    /**
     * 查询相册列表
     */
    @RequiresPermissions("system:album:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizAlbum bizAlbum)
    {
        startPage();
        List<BizAlbum> list = bizAlbumService.selectBizAlbumList(bizAlbum);
        return getDataTable(list);
    }

    /**
     * 导出相册列表
     */
    @RequiresPermissions("system:album:export")
    @Log(title = "相册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizAlbum bizAlbum)
    {
        List<BizAlbum> list = bizAlbumService.selectBizAlbumList(bizAlbum);
        ExcelUtil<BizAlbum> util = new ExcelUtil<BizAlbum>(BizAlbum.class);
        return util.exportExcel(list, "album");
    }

    /**
     * 新增相册
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存相册
     */
    @RequiresPermissions("system:album:add")
    @Log(title = "相册", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizAlbum bizAlbum)
    {
        return toAjax(bizAlbumService.insertBizAlbum(bizAlbum));
    }

    /**
     * 修改相册
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BizAlbum bizAlbum = bizAlbumService.selectBizAlbumById(id);
        mmap.put("bizAlbum", bizAlbum);
        return prefix + "/edit";
    }

    /**
     * 修改保存相册
     */
    @RequiresPermissions("system:album:edit")
    @Log(title = "相册", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizAlbum bizAlbum)
    {
        return toAjax(bizAlbumService.updateBizAlbum(bizAlbum));
    }

    /**
     * 删除相册
     */
    @RequiresPermissions("system:album:remove")
    @Log(title = "相册", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizAlbumService.deleteBizAlbumByIds(ids));
    }
}
